// 在这里启动一个主进程程序代码

import path from 'path';
import { utilityProcess, BrowserWindow } from 'electron';

export interface ProcessMessage {
    type: string;
}

class HttpProcess {
    #mainWindow!: BrowserWindow;
    #childProcess!: Electron.UtilityProcess;
    public start(mainWindow: BrowserWindow): Electron.UtilityProcess {
        this.#mainWindow = mainWindow;
        this.#childProcess = utilityProcess.fork(
            path.resolve(__dirname, './index.js')
        );
        this.listener();
        return this.#childProcess;
    }
    public listener() {
        this.#childProcess.on('message', (value: string) => {
            console.log(value);
        });
    }
}

export default new HttpProcess();
